package com.microservices.cloud.controller;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class FlowLimitController {

    @GetMapping("/testA")
    public String testA() {
//        try {
//            Thread.sleep(1000);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        log.info("testA" + Thread.currentThread().getName());
        return "-----------------------testA";
    }


    @GetMapping("/testB")
    public String testB() {
        return "-----------------------testB";
    }


    @GetMapping("/testD")
    public String testD() {
        log.info("testD-------熔断测试");
//        try {
//            Thread.sleep(1000);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        int age = 10 / 0;
        return "-----------------------testD";
    }


    @GetMapping("/testE")
    @SentinelResource(value = "testE", blockHandler = "deal_testEHandler")
    public String testE(@RequestParam(value = "p1", required = false) String p1, @RequestParam(value = "p2", required = false) String p2) {
        log.info("testE-------熔断测试");
        return "-----------------------testE";
    }

    //兜底的方法
    public String deal_testEHandler(String p1, String p2, BlockException blockException) {
        return "您好热点配置异常了";
    }


}
